import type {
  SourceTrackCategoryForm,
  SourceTrackCategoryQuery,
  SourceTrackCategoryVO,
} from './model';

import type { ID, IDS, PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 分页查询来源追踪分类列表
 * @param params
 * @returns 来源追踪分类列表
 */
export function sourceTrackCategoryPage(params?: SourceTrackCategoryQuery) {
  return requestClient.get<PageResult<SourceTrackCategoryVO>>(
    '/register/source/track/category/page',
    { params },
  );
}

/**
 * 查询来源追踪分类列表
 * @param params
 * @returns 来源追踪分类列表
 */
export function sourceTrackCategoryList(params?: SourceTrackCategoryQuery) {
  return requestClient.get<SourceTrackCategoryVO[]>(
    '/register/source/track/category/list',
    { params },
  );
}

/**
 * 导出来源追踪分类列表
 * @param params
 * @returns 来源追踪分类列表
 */
export function sourceTrackCategoryExport(params?: SourceTrackCategoryQuery) {
  return commonExport('/register/source/track/category/export', params ?? {});
}

/**
 * 查询来源追踪分类详情
 * @param id id
 * @returns 来源追踪分类详情
 */
export function sourceTrackCategoryInfo(id: ID) {
  return requestClient.get<SourceTrackCategoryVO>(
    `/register/source/track/category/${id}`,
  );
}

/**
 * 新增来源追踪分类
 * @param data
 * @returns void
 */
export function sourceTrackCategoryAdd(data: SourceTrackCategoryForm) {
  return requestClient.postWithMsg<void>(
    '/register/source/track/category',
    data,
  );
}

/**
 * 更新来源追踪分类
 * @param data
 * @returns void
 */
export function sourceTrackCategoryUpdate(data: SourceTrackCategoryForm) {
  return requestClient.putWithMsg<void>(
    '/register/source/track/category',
    data,
  );
}

/**
 * 更新来源追踪分类状态
 * @param data
 * @returns void
 */
export function sourceTrackCategoryUpdateStatus(
  data: Partial<SourceTrackCategoryVO>,
) {
  const requestData = {
    id: data.id,
    status: data.status,
  };
  return requestClient.putWithMsg<void>(
    `/register/source/track/category/changeStatus`,
    requestData,
  );
}

/**
 * 删除来源追踪分类
 * @param id id
 * @returns void
 */
export function sourceTrackCategoryRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(
    `/register/source/track/category/${id}`,
  );
}
